﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.Core.Support;
using MS.InformationManagement.Support;

namespace MS.InformationManagement.BLL.GestionDeUsuarios
{
    public class UpdateProfilePropertyCommand : IBaseCommand
    {

        #region Fields

        string _userProfileFieldName;
        string _newVaue;
        string _currentValue;
        string _currentUser;

        #endregion

        #region Constructors

        public UpdateProfilePropertyCommand(string userProfileName, string newValue, string currentUser)
        {
            _userProfileFieldName = userProfileName;
            _newVaue = newValue;
        }

        #endregion

        #region Implemented Methods

        public void Execute()
        {
            //Get current value
            _currentValue = PeopleHelper.GetPropertyUserProfile(_userProfileFieldName, _currentUser);
 
            //Updating property
            if (PeopleHelper.UpdatePropertyUserProfile(_userProfileFieldName, _newVaue, _currentUser) != true)
                throw new Exception(string.Format("Se presentaron problemas al actualizar la propiedad {0}", _userProfileFieldName));
        }

        public void Undo()
        {
            PeopleHelper.UpdatePropertyUserProfile(_userProfileFieldName, _currentValue, _currentUser);
        }

        #endregion

    }
}
